package com.awesome.common.util.device;

import android.os.Environment;
import android.os.StatFs;
import android.text.TextUtils;

import java.io.File;

/**
 * Author: JFangZ
 * Email: janezhang1901@163.com
 * Date: 2020/11/19 14:14
 * Description:SD 卡工具类
 */
public class SDCardUtil {
    /**
     * Author: JFangZ
     * Email: janezhang1901@163.com
     * Date:2020/11/19 14:19
     * Description:判断 SD 卡是否挂载
     */
    public static boolean isMounted() {
        return TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED);
    }

    /**
     * Author: JFangZ
     * Email: janezhang1901@163.com
     * Date:2020/11/19 14:19
     * Description:获取 SD 卡根路径
     */
    public static File getRoot() {
        return Environment.getExternalStorageDirectory();
    }

    /**
     * Author: JFangZ
     * Email: janezhang1901@163.com
     * Date:2020/11/19 14:19
     * Description:获取 SD 卡总容量
     */
    public static long getTotalSize() {
        return new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()).getTotalBytes();
    }

    /**
     * Author: JFangZ
     * Email: janezhang1901@163.com
     * Date:2020/11/19 14:19
     * Description:获取 SD 卡可用容量
     */
    public static long getAvailableSize() {
        return new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()).getAvailableBytes();
    }
}
